<template>
  <div @keyup.enter="getData()">
    <el-form class="query-form" :inline="true" :model="params">
      <el-form-item>
        <el-input v-model="params.customer_name" placeholder="主体名称查询" clearable></el-input>
      </el-form-item>

      <el-form-item>
        <el-button @click="getData()">
          <i class="fa fa-fw fa-search"></i>
          查询
        </el-button>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="dialogImportVisible = true">
          <i class="fa fa-fw fa-upload"></i>
          {{ importTitle }}
        </el-button>
      </el-form-item>
    </el-form>

    <c-table border v-loading="loading" :columns="tableColumns" :data="tableData"></c-table>

    <div class="query-pagination">
      <el-pagination
        @current-change="getData"
        :current-page.sync="params.index"
        :page-size="params.size"
        layout="total, prev, pager, next, jumper"
        :total="totalCount"
      ></el-pagination>
    </div>

    <import-excel
      :visible.sync="dialogImportVisible"
      :title="importTitle"
      :post-api="postUrl"
      :excel-template="excelTemplateUrl"
      @success="getData"
    ></import-excel>
  </div>
</template>
<script>
import ImportExcel from '@/components/ImportExcel'
import { mapGetters } from 'vuex'
import { queryTrouble } from '@vimi/utils-api'

export default {
  components: {
    ImportExcel,
  },
  props: {},
  data() {
    return {
      postUrl: '',
      importTitle: '导入审批登记',
      excelTemplateUrl: '/static/files/审批登记导入模板.xlsx',
      dialogImportVisible: false,

      loading: false,
      params: {
        index: 1,
        size: 10,
        customer_name: '',
        'service_id.eq': '',
      },
      tableName: 'credit_level_review',
      tableData: [],
      totalCount: 0,
      tableColumns: [
        { attrs: { label: '客户名字', prop: 'customer_name', minWidth: '200px' } },
        { attrs: { label: '批复文件号', prop: 'reply_no' } },
        { attrs: { label: '批复金额', prop: 'reply_funds' } },
        { attrs: { label: '放款时间', prop: 'load_date' } },
        { attrs: { label: '担保结束时间', prop: 'load_end_date' } },
        { attrs: { label: '担保期限(年)', prop: 'warranty_period ' } },
        { attrs: { label: '反担保方式', prop: 'warranty_method', minWidth: '360px' } },
        { attrs: { label: '担保利率', prop: 'warranty_rate' } },
        { attrs: { label: '借款银行', prop: 'bank_name' } },
        { attrs: { label: '银行联系人', prop: 'bank_concat' } },
        { attrs: { label: '银行联系人电话', prop: 'bank_concat_phone' } },
        { attrs: { label: '委托合同号', prop: 'com_contract' } },
        { attrs: { label: '借款合同号', prop: 'load_contract' } },
        { attrs: { label: '保证合同号', prop: 'gua_contract' } },
        { attrs: { label: '担保意向函', prop: 'letter_intent' } },
        { attrs: { label: '放款通知书', prop: 'loan_notice' } },
        { attrs: { label: '反担保合同号', prop: 'warranty_contract' } },
        { attrs: { label: '项目主审', prop: 'project_chief' } },
        { attrs: { label: '项目辅审', prop: 'project_aux' } },
        { attrs: { label: '有权人审批意见', prop: 'approval_option' } },
        { attrs: { label: '风控人审批意见', prop: 'risk_option' } },
        { attrs: { label: '有权人姓名', prop: 'approval_option_person' } },
        { attrs: { label: '风控人姓名', prop: 'risk_option_person' } },
        { attrs: { label: '借款利率', prop: 'load_rate' } },
      ],
    }
  },
  computed: {
    ...mapGetters(['clientId', 'job']),
    superJob() {
      return [
        'org_credit_super',
        'org_c_manage',
        'org_r_manage',
        'org_p_manage',
        'org_c_general',
      ].includes(this.job)
    },
  },
  watch: {},
  created() {
    this.params['service_id.eq'] = this.clientId
    this.postUrl =
      '/api/credit/import/' +
      queryTrouble(this.tableName, {
        importKey: `${this.tableName}_template`,
        'service_id.eq': this.clientId,
        'customer_related_id.eq': 'relatedId',
      })

    this.getData()
  },
  mounted() {},
  methods: {
    async getData() {
      this.loading = true
      let [res, err] = await this.$utils.promise(
        this.$api.getData('credit', `${this.tableName}_view`, this.params, { create_time: 'desc' })
      )
      this.loading = false

      if (err) {
        return this.$message.error('获取数据失败，请稍后重试！')
      }

      const data = (res && res.data) || {}
      this.tableData = data.data || []
      this.totalCount = data.totalCount || 0
    },
  },
}
</script>
<style scoped></style>
